package de.lang.rollo.controller.model.daos;

import java.util.Iterator;
import java.util.List;

import org.mongojack.JacksonDBCollection;
import org.mongojack.WriteResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.lang.rollo.controller.managed.MongoManaged;
import de.lang.rollo.controller.model.RolloEvent;
import de.lang.rollo.controller.model.RolloMotor;
import de.lang.rollo.controller.model.Schalter;

public class MotorDAO {
private static Logger logger = LoggerFactory.getLogger(RolloMotor.class);
	
	private JacksonDBCollection<RolloEvent, String> events;
	private JacksonDBCollection<RolloMotor, String> motoren;
	private JacksonDBCollection<Schalter, String> schalter;

	public MotorDAO() {
		events = MongoManaged.getEvents();
		motoren = MongoManaged.getMotoren();
		schalter = MongoManaged.getSchalter();
	}

	public List<RolloMotor> getAllMotoren() {
		List<RolloMotor> list = motoren.find().toArray();
		Iterator<RolloMotor> it = list.iterator();
		while (it.hasNext()) {
			RolloMotor s = it.next();
		}
		return list;
	}

	public String insertRolloMotor(RolloMotor s) {
		if (s.getId() == null){
				WriteResult<RolloMotor, String> result = motoren.insert(s);
				return result.getSavedId();
			} else {
				return null;
			}
	}
	
	public String updateMotor(RolloMotor m){
		WriteResult<RolloMotor, String> result =  motoren.updateById(m.getId(), m);
		return m.getId();
	}


}
